<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
<!-- android-building.qdoc -->
  <title>Qt for Android - Building from Source | Qt 5.14</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="index.html">Qt 5.14</a></td><td >Qt for Android - Building from Source</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.14.2 Reference Documentation</td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#installing-the-android-sdk-and-ndk-on-linux">Installing the Android SDK and NDK on Linux</a></li>
<li class="level2"><a href="#scripted-installation">Scripted Installation</a></li>
<li class="level2"><a href="#manual-installation">Manual Installation</a></li>
<li class="level2"><a href="#building-qt-for-android-on-linux">Building Qt for Android on Linux</a></li>
<li class="level1"><a href="#installing-the-android-sdk-and-ndk-on-windows">Installing the Android SDK and NDK on Windows</a></li>
<li class="level2"><a href="#step-1-setting-up-the-development-environment">Step 1: Setting up the Development Environment</a></li>
<li class="level2"><a href="#building-qt-for-android-on-windows">Building Qt for Android on Windows</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Qt for Android - Building from Source</h1>
<span class="subtitle"></span>
<!-- $$$android-building.html-description -->
<div class="descr"> <a name="details"></a>
<p>You can download the Qt 5 sources from the <a href="http://qt.io/download">Downloads</a> page. For more information, visit the <a href="gettingstarted.html">Getting Started with Qt</a> page.</p>
<p>Qt for Android has some requirements that are described in more detail in <a href="android-getting-started.html">Getting Started with Qt for Android</a>.</p>
<a name="installing-the-android-sdk-and-ndk-on-linux"></a>
<h2 id="installing-the-android-sdk-and-ndk-on-linux">Installing the Android SDK and NDK on Linux</h2>
<p>On Linux, you can install the Android SDK and NDK in one of two ways:</p>
<ol class="1" type="1"><li><a href="android-building.html#scripted-installation">via scripted installation for Linux</a></li>
<li><a href="android-building.html#manual-installation">via manual installation</a></li>
</ol>
<a name="scripted-installation"></a>
<h3 id="scripted-installation">Scripted Installation</h3>
<p>For any Debian-based Linux, use the following command:</p>
<pre class="cpp">

  apt install build<span class="operator">-</span>essential android<span class="operator">-</span>sdk

</pre>
<p>If you require openjdk, add <code>default-jdk-headless</code> to the command above.</p>
<p>It's recommended to install the NDK using sdkmanager, with the following commands:</p>
<pre class="cpp">

  sdkmanager <span class="operator">-</span><span class="operator">-</span>verbose <span class="operator">-</span><span class="operator">-</span>licenses
  sdkmanager <span class="operator">-</span><span class="operator">-</span>update
  sdkmanager <span class="string">&quot;platforms;android-28&quot;</span> <span class="string">&quot;ndk-bundle&quot;</span> <span class="string">&quot;build-tools;28.0.3&quot;</span> <span class="string">&quot;platform-tools&quot;</span> <span class="string">&quot;tools&quot;</span>

</pre>
<a name="manual-installation"></a>
<h3 id="manual-installation">Manual Installation</h3>
<ol class="1" type="1"><li>Download Android Studio from <a href="https://developer.android.com/studio/index.html">https://developer.android.com/studio/index.html</a>.</li>
<li>Open Android Studio and run the SDK Manager tool from <b>Tools &gt; Android &gt; SDK Manager</b>. If this toolbar isn't visible, you can enable it from the <b>View</b> menu: select <b>Toolbar</b>.</li>
<li>Download the Android NDK from <a href="https://developer.android.com/tools/sdk/ndk/index.html">https://developer.android.com/tools/sdk/ndk/index.html</a>.<p><b>Note: </b>As of Qt 5.12, Android NDK r18 is required and gcc toolchains are no longer supported.</p></li>
<li>Ensure that the NDK supports the API level you're targeting. To verify, check your <i>path_to_NDK/platforms</i> directory.<p><b>Note: </b>As of Qt 5.13, any API level &gt;= 21 is sufficient.</p></li>
<li>Install a JDK with a version of 1.6 or newer from <a href="https://www.oracle.com/technetwork/java/javase/downloads/index.html">https://www.oracle.com/technetwork/java/javase/downloads/index.html</a>. Alternatively, you can use OpenJDK.<pre class="cpp">

  apt<span class="operator">-</span>get install openjdk<span class="operator">-</span><span class="number">8</span><span class="operator">-</span>jdk

</pre>
</li>
</ol>
<a name="building-qt-for-android-on-linux"></a>
<h3 id="building-qt-for-android-on-linux">Building Qt for Android on Linux</h3>
<ol class="1" type="1"><li>If you have a commercially licensed Qt, install your license file. If you're using a binary installer or the commercial Qt Creator, your licenses are automatically fetched and stored in your local user profile: <code>$XDG_DATA_HOME/Qt/qtlicenses.ini</code>. Alternatively, you can download the respective license file from your Qt Account Web portal and save it to your user profile as <code>$HOME/.qt-license</code>. If you prefer a different location or file name, you need to set the <code>QT_LICENSE_FILE</code> environment variable to the respective file path.</li>
<li>Next, unpack the archive. If you have the <code>qt-everywhere-opensource-src-%VERSION%.tar.gz</code> package, type the following commands at a command line prompt:<pre class="cpp">

  cd <span class="operator">/</span>tmp
  gunzip qt<span class="operator">-</span>everywhere<span class="operator">-</span>opensource<span class="operator">-</span>src<span class="operator">-</span><span class="operator">%</span>VERSION<span class="operator">%</span><span class="operator">.</span>tar<span class="operator">.</span>gz    <span class="preprocessor"># uncompress the archive</span>
  tar xvf qt<span class="operator">-</span>everywhere<span class="operator">-</span>opensource<span class="operator">-</span>src<span class="operator">-</span><span class="operator">%</span>VERSION<span class="operator">%</span><span class="operator">.</span>tar      <span class="preprocessor"># unpack it</span>

</pre>
<p>This creates the <code>/tmp/qt-everywhere-opensource-src-%VERSION%</code> directory containing the files from the archive. We only support the GNU version of the <code>tar</code> archiving utility; also known as <code>gtar</code> on some systems.</p>
</li>
<li>Configure the <code>JAVA_HOME</code> environment variable. You need to set it and add it to your <code>PATH</code>; preferably at the end of <code>~/.profile</code>:<pre class="cpp">

  <span class="keyword">export</span> JAVA_HOME<span class="operator">=</span><span class="operator">/</span>usr<span class="operator">/</span>lib<span class="operator">/</span>jvm<span class="operator">/</span>java<span class="operator">-</span><span class="number">8</span><span class="operator">-</span>openjdk<span class="operator">-</span>amd64
  <span class="keyword">export</span> PATH<span class="operator">=</span>$PATH:$JAVA_HOME<span class="operator">/</span>bin

</pre>
</li>
<li>Next, configure Qt with the following command:<pre class="cpp">

  <span class="operator">.</span><span class="operator">/</span>configure <span class="operator">-</span>xplatform android<span class="operator">-</span>clang <span class="operator">-</span><span class="operator">-</span>disable<span class="operator">-</span>rpath <span class="operator">-</span>nomake tests <span class="operator">-</span>nomake examples
  <span class="operator">-</span>android<span class="operator">-</span>ndk <span class="operator">&lt;</span>path<span class="operator">/</span>to<span class="operator">/</span>ndk<span class="operator">&gt;</span> <span class="operator">-</span>android<span class="operator">-</span>sdk <span class="operator">&lt;</span>path<span class="operator">/</span>to<span class="operator">/</span>sdk<span class="operator">&gt;</span> <span class="operator">-</span>no<span class="operator">-</span>warnings<span class="operator">-</span>are<span class="operator">-</span>errors

</pre>
<p>You may provide the <code>-android-abis</code> parameter to limit the Android ABIs targeted, such as armeabi-v7a, arm64-v8a, x86, or x86_64:</p>
<pre class="cpp">

  <span class="operator">-</span>android<span class="operator">-</span>abis armeabi<span class="operator">-</span>v7a<span class="operator">,</span>arm64<span class="operator">-</span>v8a

</pre>
<p>If the parameter is not specified, Qt is built for all supported ABIs.</p>
</li>
<li>To build the parts of Qt you have now configured run the following command. <i>nproc</i> is optional, representing the number of parallel jobs your system can do.<pre class="cpp">

  make <span class="operator">-</span>j$(nproc)

</pre>
</li>
<li>To install the parts of Qt you have built, run:<pre class="cpp">

  make install

</pre>
<p>If you haven't used the <code>--prefix &lt;install-dir&gt;</code> configure option, the installation is placed under <code>/usr/local/Qt-&lt;version&gt;</code>. In Debian/Ubuntu, you should prefix the <code>make</code> command with the <code>sudo</code> command.</p>
</li>
</ol>
<a name="installing-the-android-sdk-and-ndk-on-windows"></a>
<h2 id="installing-the-android-sdk-and-ndk-on-windows">Installing the Android SDK and NDK on Windows</h2>
<p><b>Note: </b>Currently, it is not possible to use Microsoft's compilers to build the Windows host tools for Qt Android.</p><a name="step-1-setting-up-the-development-environment"></a>
<h3 id="step-1-setting-up-the-development-environment">Step 1: Setting up the Development Environment</h3>
<ol class="1" type="1"><li>Install the latest Perl from <a href="http://strawberryperl.com">http://strawberryperl.com</a>. Then, select a destination folder, also known as <code>PERL_ROOT</code>.</li>
<li>Set up the <a href="https://mingw-w64.org/">MinGW</a> toolchain by downloading a pre-built Qt package for <a href="https://mingw-w64.org/">MinGW</a>, and then add it to your <code>PATH</code>, for example: <code>C:\dev\Qt\Tools\mingw730_64\bin</code>.</li>
<li>Install the latest JDK from <a href="https://www.oracle.com/technetwork/java/javase/downloads/index.html">https://www.oracle.com/technetwork/java/javase/downloads/index.html</a>. Then, add the <i>&lt;JDK_ROOT&gt;</i> to <code>PATH</code>. Alternatively, if you've installed Android Studio, you can use the JDK that's included in your installation's <code>jre</code> folder.</li>
<li>Install the Android NDK, r18b, from <a href="https://developer.android.com/tools/sdk/ndk/index.html">https://developer.android.com/tools/sdk/ndk/index.html</a>. Extract it to <i>&lt;ANDROID_NDK_PATH&gt;</i>.</li>
<li>Install the latest Android SDK (tools only) from <a href="http://developer.android.com/sdk/index.html">http://developer.android.com/sdk/index.html</a>. Run the Android SDK Manager and install the latest version of &quot;SDK Platform&quot;, &quot;Google APIs&quot;, and &quot;build-tools&quot; in <i>&lt;ANDROID_SDK_PATH&gt;</i>.</li>
<li>Open the <code>cmd.exe</code> window and verify that:<ul>
<li><code>where gcc.exe</code> lists <i>&lt;MINGW_ROOT&gt;.exe</i> first before <i>&lt;PERL_ROOT&gt;.exe</i>.</li>
<li><code>where mingw32-make.exe</code> lists <i>&lt;MINGW_ROOT32&gt;-make.exe</i> first.</li>
<li><code>where javac.exe</code> lists <i>&lt;JDK_ROOT&gt;</i> first.</li>
</ul>
</li>
<li>Add the following environment variables:<pre class="cpp">

  set <span class="string">&quot;ANDROID_API_VERSION=android-28&quot;</span>
  set <span class="string">&quot;ANDROID_SDK_ROOT=&lt;ANDROID_SDK_PATH&gt;&quot;</span>
  set <span class="string">&quot;ANDROID_TARGET_ARCH=armeabi-v7a&quot;</span>
  set <span class="string">&quot;ANDROID_BUILD_TOOLS_REVISION=21.1.2&quot;</span>
  set <span class="string">&quot;ANDROID_NDK_PATH=&lt;ANDROID_NDK_PATH&gt;&quot;</span>
  set <span class="string">&quot;ANDROID_TOOLCHAIN_VERSION=4.9&quot;</span>

</pre>
<p>Depending on which NDK you have downloaded, add its path:</p>
<pre class="cpp">

  set <span class="string">&quot;ANDROID_NDK_HOST=windows-x86_64&quot;</span>

</pre>
<p>or</p>
<pre class="cpp">

  set <span class="string">&quot;ANDROID_NDK_HOST=windows&quot;</span>

</pre>
</li>
</ol>
<a name="building-qt-for-android-on-windows"></a>
<h3 id="building-qt-for-android-on-windows">Building Qt for Android on Windows</h3>
<ul>
<li>If you have a commercially licensed Qt, install your license file. If you're using a binary installer or the commercial Qt Creator, your licenses are automatically fetched and stored in your local user profile: <code>%USERPROFILE%\AppData\Roaming\Qt\qtlicenses.ini</code>. Alternatively, you can download the respective license file from your Qt Account Web portal and save it to your user profile as <code>%USERPROFILE%\.qt-license</code>. If you prefer a different location or file name, you need to set the <code>QT_LICENSE_FILE</code> environment variable to the respective file path.</li>
<li>Next, unpack the archive. Uncompress the files into the directory in which you want Qt installed, for example: <code>C:\Qt\%VERSION%</code>. This install path must not contain any spaces or Windows-specific file system characters.</li>
<li>Run the following command to configure Qt:<pre class="cpp">

  configure<span class="operator">.</span>bat <span class="operator">-</span>prefix <span class="operator">&lt;</span>path to install <span class="type"><a href="../qtcore/qt.html">Qt</a></span> to<span class="operator">&gt;</span> <span class="operator">-</span>platform win32<span class="operator">-</span>g<span class="operator">+</span><span class="operator">+</span> <span class="operator">-</span>opengl es2 <span class="operator">-</span>xplatform
  android<span class="operator">-</span>clang <span class="operator">-</span>android<span class="operator">-</span>ndk <span class="operator">%</span>ANDROID_NDK_PATH<span class="operator">%</span> <span class="operator">-</span>android<span class="operator">-</span>sdk <span class="operator">%</span>ANDROID_SDK_ROOT<span class="operator">%</span> <span class="operator">-</span>nomake tests
  <span class="operator">-</span>nomake examples

</pre>
</li>
<li>To build the previously configured parts of Qt, run the following command:<pre class="cpp">

  mingw32<span class="operator">-</span>make<span class="operator">.</span>exe <span class="operator">-</span>j<span class="operator">&lt;</span>N<span class="operator">&gt;</span>

</pre>
<p><i>&lt;N&gt;</i> is optional, representing the number of parallel jobs your system can do.</p>
</li>
<li>Now, to install Qt, run the following command:<pre class="cpp">

  mingw32<span class="operator">-</span>make<span class="operator">.</span>exe install

</pre>
</li>
</ul>
</div>
<!-- @@@android-building.html -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2020 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
